package com.example.day1901;

import java.io.*;

/**
 * @author Lenovo
 */
public class ObjectStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        read();
    }

    private static void read() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new
                FileInputStream("myOtherStream\\oos.txt"));
        Object obj = ois.readObject();
        Student s = (Student) obj;
        System.out.println(s.getName() + "," + s.getAge());
        ois.close();
    }

    private static void write() throws IOException {
        Student s = new Student("张三", 20);
        ObjectOutputStream oos = new ObjectOutputStream(new
                FileOutputStream("myOtherStream\\oos.txt"));
        oos.writeObject(s);
        oos.close();
    }

    private static void write() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new
                FileOutputStream("myOtherStream\\oos.txt"));
        Student s = new Student("林青霞", 30);
        oos.writeObject(s);
        oos.close();
    }
}